package com.ibox.core.book;

import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.WindowManager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.ibox.base.BaseActivity;
import com.ibox.core.book.ui.TopRankActivity;

@Route(path = "/main/book")
public class BookHomeActivity extends BaseActivity {

    DrawerLayout mDlBook;
    Toolbar mTbBook;
    NavigationView mNvBook;
    RecyclerView mRvBook;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_book_home;
    }

    @Override
    public void initView() {
        mDlBook = findView(R.id.dlBook);
        mTbBook = findView(R.id.tbBook);
        mRvBook = findView(R.id.rvContent);
        mNvBook = findView(R.id.navBook);

        setSupportActionBar(mTbBook);
        //实现顶部状态栏透明
        WindowManager.LayoutParams localLayoutParams = getWindow().getAttributes();
        localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | localLayoutParams.flags);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, mDlBook, mTbBook, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        mDlBook.addDrawerListener(toggle);
        toggle.syncState();
        //显示图标的默认颜色
        mNvBook.setItemIconTintList(null);

    }

    @Override
    public void initData() {

    }

    @Override
    public void configViews() {
        mNvBook.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.nav_book_rank:
                        TopRankActivity.startActivity(BookHomeActivity.this);
                        break;
                    case R.id.nav_book_cate:
                        break;
                    case R.id.nav_book_list:
                        break;
                }
                mDlBook.closeDrawer(GravityCompat.START);
                return true;
            }
        });
    }

    @Override
    public void onBackPressedSupport() {
        if (mDlBook.isDrawerOpen(GravityCompat.START)) {
            mDlBook.closeDrawer(GravityCompat.START);
        } else {
            finish();
        }
    }
}
